﻿namespace Sai.Core.Sandcastle
{
	public class ProjectItem
	{
		public static readonly string ContentTag = "<Content";
		public static readonly string NoneTag = "<None";
		public static readonly string ContentLayoutTag = "<ContentLayout";
		public static readonly string IncludeEqual = "Include=";

		public ProjectItem()
		{
		}

		public ProjectItem(string path)
		{
			this.Path = path;
		}

		public string Path { get; private set; }

		public void Parse(string line)
		{
			this.Parse(line, ContentTag);
		}

		public void Parse(string line, string itemName)
		{
			if (ProjectItem.LineMatches(line, itemName))
			{
				this.Path = line.ExtractQuotedText();
			}
		}

		public override string ToString()
		{
			return string.Format("{0} Include=\"{1}\" />", ContentTag, this.Path);
		}

		public override int GetHashCode()
		{
			return this.Path.GetHashCode();
		}

		public static bool LineMatches(string line, string tagName)
		{
			return line.Trim().StartsWith(tagName);
		}

		public static bool LineMatches(string line)
		{
			return LineMatches(line, ContentTag);
		}
	}
}
